/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
	"cmdTools/pxe"
	"fmt"
	"github.com/spf13/cobra"
)

var (
	Path      string
	HostName  string
	UserName  string
	Password  string
	Interface string
	Port      int
	Server    bool
)

// pxeCmd represents the pxe command
var pxeCmd = &cobra.Command{
	Use:   "pxe",
	Short: "Common pxe operations",
	Long:  ``,
	/*	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("pxe called ", server, topic, args)

	},*/
	Run: func(cmd *cobra.Command, args []string) {
		pxe.Service()
	},
}

var ubuntu = &cobra.Command{
	Use:     "ubuntu",
	Short:   "",
	Long:    ``,
	Example: "cmdTools pxe  ",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.Service()
	},
}

var Power = &cobra.Command{
	Use:     "power",
	Aliases: []string{},
	Short:   "Show topic details",
	Long:    `Show topic details`,
	Example: "cmdTools pxe -s 10.0.103.12:31090 desctopic -t topic",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("power")
	},
}

var Status = &cobra.Command{
	Use:     "status",
	Aliases: []string{},
	Short:   "Show topic details",
	Long:    `Show topic details`,
	Example: "cmdTools pxe -s 10.0.103.12:31090 desctopic -t topic",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.Test()
	},
}

/*
var UpdatePartitionReassignments = &cobra.Command{
	Use:     "updatepartition",
	Aliases: []string{"up", "updatep"},
	Short:   "Update Partition Reassignments",
	Long:    `Update the partition distribution to balance all nodes`,
	Example: "cmdTools pxe -s 10.0.103.12:31090 up   -t topic",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.CApxeer.pxeInit(server)
		pxe.CApxeer.CreateClusterAdmin()
		pxe.CApxeer.CreateClient()
		pxe.CApxeer.UpdatePartitionReassignments(topic[0], ReplicaAssignment)
	},
}

var expandPartitionsForAll = &cobra.Command{
	Use:     "expandpartitionsforall",
	Aliases: []string{"epa", "expandpa"},
	Short:   "Extend all partitions",
	Long:    `Extend all topic partitions to the number of brokers, and reallocate balanced nodes`,
	Example: "cmdTools pxe -s 10.0.103.12:31090 expandall",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.CApxeer.pxeInit(server)
		pxe.CApxeer.CreateClusterAdmin()
		pxe.CApxeer.ExpandPartitionsForAll()
	},
}

var CreateTopic = &cobra.Command{
	Use:     "createtopic",
	Aliases: []string{"ct", "createt"},
	Short:   "Create topic",
	Long:    `Creates topic`,
	Example: "cmdTools pxe -s 10.0.103.12:31090 createt -t topic  -n 6  -d 2 ",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.CApxeer.pxeInit(server)
		pxe.CApxeer.CreateClusterAdmin()
		pxe.CApxeer.CreateTopic(topic[0], numPartition, duplicate)
	},
}

var CreatePartitions = &cobra.Command{
	Use:     "createpartition",
	Aliases: []string{"cp", "createp"},
	Short:   "Create partitions",
	Long:    `Creates a partition based on the specified partition mapping`,
	Example: "cmdTools pxe -s 10.0.103.12:31090 createp -t swyang  -n 6 -r [[0],[0],[0]] (new partition map or nil)",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.CApxeer.pxeInit(server)
		pxe.CApxeer.CreateClusterAdmin()
		pxe.CApxeer.CreatePartitions(topic[0], ReplicaAssignment, numPartition)
	},
}

var DescribeConsumerGroup = &cobra.Command{
	Use:     "describeconsumergroup ",
	Aliases: []string{"dcg", "descdcg"},
	Short:   "Display consumer group details",
	Long:    `Display consumer group details`,
	Example: "cmdTools pxe -s 10.1.100.102:31090 desccg   -c cg1,cg2",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.CApxeer.pxeInit(server)
		pxe.CApxeer.CreateClusterAdmin()
		pxe.CApxeer.CreateClient()
		pxe.CApxeer.DescribeConsumerGroup(consumerGroup)
	},
}

var ConsumerTopic = &cobra.Command{
	Use:     "consumer",
	Short:   "Consumer topic",
	Long:    `Consume a topic using the cmdToolsGroup consumption group,`,
	Example: "cmdTools pxe -s 10.1.100.102:31090 consumer -t topic -f",
	Run: func(cmd *cobra.Command, args []string) {
		pxe.CApxeer.pxeInit(server)
		pxe.CApxeer.CreateClusterAdmin()
		pxe.CApxeer.CreateClient()
		pxe.CApxeer.ConsumerTopic(topic, frist)
	},
}*/

func init() {
	/*	pxeCmd.PersistentFlags().StringSliceVarP(&server, "server", "s", []string{"localhost:9092"}, "pxe address: localhost:9092,localhost:9093")
		pxeCmd.PersistentFlags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")

		productMsg.Flags().StringVarP(&key, "key", "k", "key", "msg key")
		productMsg.Flags().StringVarP(&value, "value", "v", "value", "msg value")
		productMsg.Flags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")
		_ = productMsg.MarkFlagRequired("topic")
		_ = productMsg.MarkFlagRequired("value")
		pxeCmd.AddCommand(productMsg)

		descTopic.Flags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")
		pxeCmd.AddCommand(descTopic)

		UpdatePartitionReassignments.Flags().StringVarP(&ReplicaAssignment, "ReplicaAssignment", "r", "[]", "ReplicaAssignment: [[1,2],[0,1]]")
		UpdatePartitionReassignments.Flags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")
		_ = UpdatePartitionReassignments.MarkFlagRequired("topic")
		pxeCmd.AddCommand(UpdatePartitionReassignments)

		CreatePartitions.Flags().StringVarP(&ReplicaAssignment, "ReplicaAssignment", "r", "[]", "ReplicaAssignment: [[1,2],[0,1]]")
		CreatePartitions.Flags().IntVarP(&numPartition, "numPartition", "n", 0, "numPartition")
		CreatePartitions.Flags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")
		_ = CreatePartitions.MarkFlagRequired("topic")
		_ = CreatePartitions.MarkFlagRequired("numPartition")
		pxeCmd.AddCommand(CreatePartitions)

		pxeCmd.AddCommand(expandPartitionsForAll)

		//DescribeConsumerGroup.Flags().StringVarP(&consumerGroup, "consumerGroup", "c", "[]", "consumerGroup")
		DescribeConsumerGroup.Flags().StringSliceVarP(&consumerGroup, "consumerGroup", "c", []string{}, "consumerGroup: cg1,cg2")
		pxeCmd.AddCommand(DescribeConsumerGroup)

		//ConsumerTopic.Flags().Int64VarP(&beging, "beging", "b", -1, "offset -2 or ...")
		ConsumerTopic.Flags().BoolVarP(&frist, "frist", "f", false, "default OffsetNewest")
		ConsumerTopic.Flags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")
		_ = ConsumerTopic.MarkFlagRequired("topic")
		pxeCmd.AddCommand(ConsumerTopic)

		CreateTopic.Flags().IntVarP(&numPartition, "numPartition", "n", 1, "numPartition")
		CreateTopic.Flags().IntVarP(&duplicate, "duplicate", "d", 1, "Replication Factor")
		CreateTopic.Flags().StringSliceVarP(&topic, "topic", "t", []string{}, "pxe topic: t1,t2")
		_ = CreateTopic.MarkFlagRequired("topic")*/
	pxeCmd.AddCommand(Status)

	rootCmd.AddCommand(pxeCmd)

}
